home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 301-325 / disk_309 / sksh / stuff.sksh < prev    next >
Text File  |  1992-05-06  |  4KB  |  120 lines

  1.  
  2. #*************************************************************************
  3. # This file contains functions and aliases which can be cut out and put
  4. # in your .skshrc file.  They are not included there by default, since
  5. # many people will not want them, or will want modified versions.
  6. # These commands should operate with SKsh version 1.3 or later.
  7. # They are also simple skeletons which can be expanded to add features.
  8. #
  9. # Also, please note that these commands have not been tested extensively.
  10. #*************************************************************************
  11.  
  12.  
  13. #*************************************************************************
  14. # This is a "man" function which can be used to retrieve documentation
  15. # files stored in a MAN: directory.  These files (which are often
  16. # included with public domain software as "readme" files) should be
  17. # copied to a name such as "MAN:prog.MAN".  Then, "man prog" can be used
  18. # to retrieve the files with the "more" command.  One useful extention
  19. # would permit the use of a $PAGER variable instead of always using
  20. # "more".
  21. #*************************************************************************
  22.  
  23. function man {
  24.    if [ ! -f "MAN:$1.MAN" ]
  25.    then
  26.       echo "No manual entry for $1"
  27.    else
  28.       more "MAN:$1.MAN"
  29.    fi
  30. }
  31.  
  32.  
  33. #*************************************************************************
  34. #  This function accepts a number of parameters, and prompts the user
  35. #  for whether these files should be deleted.  For example, "qrm *.o"
  36. #  would prompt the user at each .o file.  Answering "Y" or "y" causes
  37. #  the file to be removed; otherwise, it is ignored.  A useful extention
  38. #  would look at only the first character of the response, thus allowing
  39. #  "yes" to be used in place of "y".
  40. #*************************************************************************
  41.  
  42. function qrm {    # query rm
  43.    local ans
  44.  
  45.    for file in $*
  46.    do
  47.       echo -n "Remove $file ? "
  48.       read ans
  49.  
  50.       if [ "$ans" = 'y' -o "$ans" = 'Y' ]
  51.       then
  52.          rm -v "$file"
  53.       fi
  54.    done
  55. }
  56.  
  57.  
  58. #*************************************************************************
  59. # This alias will remove emacs backup files by using the "qrm" function
  60. # defined above.  It could be extended to remove ".o" files, or anything
  61. # else.
  62. #*************************************************************************
  63.  
  64. alias clean='qrm *~'
  65.  
  66.  
  67. #*************************************************************************
  68. # The following functions implement directory push and pop operations.
  69. # The first, pushd, accepts one argument.  It cd's to that directory, but
  70. # pushes the current working directory onto a stack, first, so that it
  71. # can later be retrieved with a popd.
  72. #*************************************************************************
  73.  
  74. function pushd {
  75.    if [ $# -ne 1 ]
  76.    then
  77.       echo "Usage: $0 new_dir"
  78.    else
  79.       DIRSTACK="$PWD,$DIRSTACK"
  80.       export DIRSTACK
  81.       cd "$1"
  82.    fi
  83. }
  84.  
  85. #*************************************************************************
  86. # This function implements the popd operation.  It accepts no arguments,
  87. # and simply pops a directory off the stack and returns to that point.
  88. # it complains if the directory stack is empty.
  89. #*************************************************************************
  90.  
  91. function popd {
  92.    local comma_pos new_dir
  93.  
  94.    if [ $# -ne 0 ]
  95.    then
  96.       echo "Usage: $0"
  97.       return
  98.    elif [ -z "$DIRSTACK" ]
  99.    then
  100.       echo 'The directory stack is empty'
  101.       return
  102.    fi
  103.       
  104.    comma_pos = $(expr index "$DIRSTACK" ',')
  105.    new_dir   = $(expr substr "$DIRSTACK" 1 $(expr $comma_pos - 1))
  106.    DIRSTACK  = $(expr substr "$DIRSTACK" $(expr $comma_pos + 1) 32000)
  107.    export DIRSTACK
  108.    cd "$new_dir"
  109. }
  110.  
  111.  
  112. #*************************************************************************
  113. # These aliases clear and print the directory stack, respectively.  The
  114. # directory stack will be printed with a trailing comma, which is how it
  115. # is stored.  This could be cleaned up quite simply.
  116. #*************************************************************************
  117.  
  118. alias cleard='DIRSTACK=""'
  119. alias dstack='echo "$DIRSTACK"'
  120.